package com.bwie.controller;

import com.bwie.pojo.Shop;
import com.bwie.pojo.ShopParam;
import com.bwie.service.ShopService;
import com.bwie.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Mikey
 * @Date: 2025/9/9 11:46
 * @Description:
 **/
@Api(tags = "商铺管理")
@RestController
@RequestMapping("shop/index")
public class ShopController {

    @Autowired
    private ShopService shopService;


    /***
     * @author: 秋晚
     * @description:查询商品列表 （管理员可以看到全部商铺   普通用户只能看到自已旗下商铺）
     * @params: [com.bwie.pojo.ShopParam]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 11:51
     */
    @ApiOperation("查询商铺列表")
    @PostMapping("getShopList")
    public R getShopList(@RequestBody ShopParam shopParam){
        return shopService.getShopList(shopParam);
    }


    /***
     * @author: 秋晚
     * @description:添加商铺
     * @params: [com.bwie.pojo.ShopParam]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 12:51
     */
    @ApiOperation("添加商铺")
    @PostMapping("saveShop")
    public R saveShop(@RequestBody @Validated Shop shop){
        if(shop.getSecurityMoney().equals(0)){
            //未缴纳200
            return R.ERROR(500,"未缴纳保证金不能添加商铺");
        }
        return shopService.saveShop(shop);
    }



    /***
     * @author: 秋晚
     * @description:根据id续约
     * @params: [java.lang.Integer]
     * @return: com.bwie.utils.R
     * @date: 2025/9/9 17:40
     */
    @PostMapping("reContract/{id}")
    public R reContract(@PathVariable(name = "id")Integer id){
        return shopService.reContract(id);
    }
}